<template>
  <div>
    <h1>问卷管理</h1>
    <el-button type="text" @click="questionnaireins()">新增/修改</el-button>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="questionaireId"
        label="问卷id"
        width="180">
      </el-table-column>
      <el-table-column
        prop="questionnaireName"
        label="评测"
        width="180">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button @click="QuestionnaireDeleted(scope.row.questionaireId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form :model="tbQuestionnaire" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="请输入问卷id">
          <el-input v-model="tbQuestionnaire.questionaireId"></el-input>
        </el-form-item>
        <el-form-item label="请输入问卷的名字">
          <el-input v-model="tbQuestionnaire.questionnaireName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="QuestionnaireUpdate()">修改</el-button>
          <el-button type="primary" @click="QuestionnaireInsert()">新增</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {QuestionnaireSelect,QuestionnaireDeleted,QuestionnaireInsert,QuestionnaireUpdate} from '@/api/evaluating'
  export default {
    data() {
      return {
        dialogVisible:false,
        tableData: [],
        tbQuestionnaire:{
          questionaireId:'',
          questionnaireName:''
        }
      }
    },
    mounted(){
      this.QuestionnaireSelect()
    },
    methods:{
      questionnaireins(){
        this.dialogVisible=true
      },
      QuestionnaireSelect(){
      QuestionnaireSelect(this.tbQuestionnaire).then((res)=>{
          console.log(res.data)
        this.tableData=res.data
        })
      },
      QuestionnaireDeleted(row){
        QuestionnaireDeleted(row).then((res)=>{
          console.log(res.data)
          this.QuestionnaireSelect()
        })
      },
      QuestionnaireInsert(){
        this.tbQuestionnaire.questionaireId=null
        this.dialogVisible=false
        QuestionnaireInsert(this.tbQuestionnaire).then((res)=>{
          console.log(res.data)
          this.tbQuestionnaire=[]
          this.QuestionnaireSelect()
        })
      },
      QuestionnaireUpdate(){
        this.dialogVisible=false
        QuestionnaireUpdate(this.tbQuestionnaire).then((res)=>{
          console.log(res.data)
          this.QuestionnaireSelect()
        })
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      }
    }
  }
</script>

<style scoped></style>

